//
//  GGBaseTableVC.swift
//  DongBaoDemo
//
//  Created by 陈志勇 on 2018/8/5.
//  Copyright © 2018年 陈志勇. All rights reserved.
//

import UIKit

class GGBaseTableVC: UITableViewController {
    
    var point = CGPoint.zero
    var canScroll = false
    
    var fingerIsTouch = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "baseCell")
        tableView.separatorStyle = .none
    }
    
}

extension GGBaseTableVC {
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 30
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "baseCell", for: indexPath)
        cell.textLabel?.text = "对今后将\(indexPath.row)"
        return cell
    }
    
}

extension GGBaseTableVC {
    
    override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        fingerIsTouch = true
    }
    
    override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        fingerIsTouch = false
    }
    
    override func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if canScroll == false {
            scrollView.contentOffset = CGPoint.zero
        }
        if scrollView.contentOffset.y <= 0 {
            canScroll = false
            scrollView.contentOffset = CGPoint.zero
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "leaveTop"), object: nil) // 到顶通知父视图改变状态
        }
        tableView.showsVerticalScrollIndicator = canScroll
    }
    
}
